package com.lihui.dao;

import com.lihui.model.Score;
import com.lihui.util.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * 功能描述
 *
 * @author wileda
 * @date 2022/12/29  17:08
 */
public class ScoreDao {
    public void insert(Score score){
        Connection connection = null;
        PreparedStatement statement = null;

        try {
            connection = DBUtil.getConnection();
            String sql = "insert into score(score,student_id,course_id) values(?,?,?)";
            statement = connection.prepareStatement(sql);
            statement.setBigDecimal(1,score.getScore());
            statement.setInt(2,score.getStudentId());
            statement.setInt(3,score.getCourseId());
            int result = statement.executeUpdate();
            if(result > 0){
                System.out.println("添加成功");
            }else {
                System.out.println("添加失败");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            DBUtil.close(null,statement,connection);
        }
    }
}
